//
//  TravelTourImagePicViewController.m
//  ToWhere
//
//  Created by dllo on 15/11/21.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelTourImagePicViewController.h"

#import "TravelTourSmallModel.h"
#import <SDWebImageManager.h>
#import <UIImageView+WebCache.h>
#import "TravelTourImageViewCollectionViewCell.h"
#import "TravelTourImageCollectionCell.h"
#import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>


@interface TravelTourImagePicViewController ()<UIScrollViewDelegate, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout,TravelTourImageCollectionCell>

@property (nonatomic, retain) UICollectionView *collectionView;

@property (nonatomic, retain) AVPlayer *player;

@property (nonatomic, retain) UIScrollView *scrollView;

@property (nonatomic, retain) UILabel *labelDes;

@end

@implementation TravelTourImagePicViewController

-(void)dealloc
{
    
    [_collectionView release];
    [_arr release];
    [_collectionView release];
    [_labelDes release];
    
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createCollectionView];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(10*kWidth, 30 *kHeight, 40*kWidth, 20 *kHeight);
    [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    //btn.backgroundColor = [UIColor redColor];
    [btn setImage:[UIImage imageNamed:@"Food_back"] forState:UIControlStateNormal];

    [self.view addSubview:btn];
   
}




-(void)btnAction
{
    [self.player pause];
    [self.navigationController popViewControllerAnimated:YES];
    
}



#pragma mark 创建colleView
-(void)createCollectionView
{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  
   [layout setScrollDirection:
UICollectionViewScrollDirectionHorizontal];
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64 *kHeight, self.view.frame.size.width, self.view.frame.size.height - 64 *kHeight) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource =self;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.pagingEnabled = YES;
   
    [self.collectionView registerClass:[TravelTourImageViewCollectionViewCell class] forCellWithReuseIdentifier:@"TravelTourImageViewCollectionViewCell"];
    
    [self.collectionView registerClass:[TravelTourImageCollectionCell class] forCellWithReuseIdentifier:@"TravelTourImageCollectionCell"];
    
    self.collectionView.contentOffset = CGPointMake(375 *self.number, 0);
    [self.view addSubview:self.collectionView];
    [_collectionView release];
    
    
}

#pragma marl
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
#pragma mark 返回cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if ([[self.arr[indexPath.row] photo_url] length] !=0) {
        TravelTourImageViewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TravelTourImageViewCollectionViewCell" forIndexPath:indexPath];
        cell.model = self.arr[indexPath.row];
        return cell;

    }else{
        TravelTourImageCollectionCell * cell= [collectionView dequeueReusableCellWithReuseIdentifier:@"TravelTourImageCollectionCell" forIndexPath:indexPath];
        cell.model= self.arr [indexPath.row];
        cell.delegate = self;
        return cell;
    }
   }

-(void)string:(NSString *)url
{
//    NilViewController *view = [[NilViewController alloc]init];
//    
//    view.url = url;
//    
//    [self presentViewController:view animated:YES completion:nil];


    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:url]];
    moviePlayer.view.frame = self.view.frame;
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];
}




#pragma mark 返回数量
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    return self.arr.count;
    
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0 *kWidth;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0 * kHeight;
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
        return UIEdgeInsetsMake(0, 0,0, 0);
   
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    
        return CGSizeMake(375 *kWidth, 637 *kHeight);
  
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
  
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
  
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
